﻿using System;
using System.Windows.Media;
using System.Windows.Data;

namespace ReflectionStudio.Controls
{
    /// <summary>
    /// Converter : Enum to string and revert
    /// </summary>
    [ValueConversion(typeof(object), typeof(object))]
    public class String2ColorConverter : IValueConverter
    {
        /// <summary>
        /// IValueConverter.Convert
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            if (value == null)
            {
                value = "0";
            }
            string v = value.ToString();
            object vR = new SolidColorBrush(Colors.White);
            if (v == "1")
            {
                vR = new SolidColorBrush(Colors.Black);
                vR = Colors.Black;
            }
            return vR;
        }

        /// <summary>
        /// IValueConverter.ConvertBack
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return "0";
            if (value == null)
                return "0";
            if (value.GetType().ToString() != "SolidColorBrush")
                return "0";
            if (((SolidColorBrush)value).Color == Colors.Black)
                return "1";
            else
                return "0";
        }
    }

    [ValueConversion(typeof(object), typeof(object))]
    public class ClolorGrade : IValueConverter
    {
        /// <summary>
        /// IValueConverter.Convert
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            if (value == null)
            {
                value = "1";
            }
            if (value == "")
            {
                value = "1";
            }
            int v = int.Parse(value.ToString());
            if (v == 0)
                v = 1;
            byte c = byte.Parse((Math.Round(System.Convert.ToDouble(50*v), 0)).ToString());
            Color color = Color.FromRgb(c, c,50); 
            return color;
        }

        /// <summary>
        /// IValueConverter.ConvertBack
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }

    [ValueConversion(typeof(object), typeof(object))]
    public class WDColorGrade : IValueConverter
    {
        /// <summary>
        /// IValueConverter.Convert
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            if (value == null)
            {
                value = "0";
            }
            if (value == "")
            {
                value = "0";
            } 
            byte c = System.Convert.ToByte(255-int.Parse( value.ToString()));
            Color color = Color.FromRgb(255, c, c);
            return color;
        }

        /// <summary>
        /// IValueConverter.ConvertBack
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }
    [ValueConversion(typeof(object), typeof(object))]
    public class YGGrade : IValueConverter
    {
        /// <summary>
        /// IValueConverter.Convert
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            if (value == null)
            {
                value = "0";
            }
            if (value == "")
            {
                value = "0";
            } 
            Color color = Color.FromRgb(255, 255, 200);
            if (value.ToString().Trim() == "1")
            {
                color= Color.FromRgb(255, 255, 50);
            }
            
           
            return color;
        }

        /// <summary>
        /// IValueConverter.ConvertBack
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }

    [ValueConversion(typeof(object), typeof(object))]
    public class EearlyEndGrade : IValueConverter
    {
        /// <summary>
        /// IValueConverter.Convert
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            if (value == null)
            {
                value = "0";
            }
            if (value == "")
            {
                value = "0";
            }
            Color color = Color.FromRgb(255, 255, 255);
            if (double.Parse(value.ToString())<0)
            {
                color = Color.FromRgb(255, 0, 0);
            } 

            return color;
        }

        /// <summary>
        /// IValueConverter.ConvertBack
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }
}
